package com.jz.dsq.utils;

import java.util.Arrays;

/**
 * @author ZhangLiang
 * @date 2020/05/13
 */
public enum Operator {
    /**
     * filed = value
     */
    eq("eq"),
    /**
     * filed!= value
     */
    ne("ne"),

    /**
     * filed > value
     */
    gt("greaterThan"),
    /**
     * field >= value
     */
    ge("greaterThanOrEqualTo"),
    /**
     * field < value
     */
    lt("lessThan"),
    /**
     * field <= value
     */
    le("lessThanOrEqualTo"),

    /**
     * field like value
     */
    like("like"),
    /**
     * field not like value
     */
    notLike("notLike"),
    /**
     * between value1 and value2 ,Type is Date
     */
    between("between"),

    in("in"),
    notIn("notIn"),

    /**
     * 无比较值情况
     **/
    isNull("isNull"),
    isNotNull("isNotNull");

    private final String key;

    Operator(String key) {
        this.key = key;
    }

    public String getKey() {
        return key;
    }


    /**
     * 获取sql操作
     *
     * @param key :
     * @return com.bluewhitetoy.system.common.util.autosearchutils.Operator
     * @author zhangliang
     */
    public static Operator getEnumType(String key) {
        return Arrays.stream(Operator.values())
                .filter(operator -> operator.getKey().equals(key))
                .findFirst().orElse(eq);
    }


}
